var cookie = require('./cookie')();
module.exports = function() {
  // set background img
  var cookie_name = 'xxoo';
  if(window.headerBg && window.headerBg != undefined) {
    var header_bg_array = headerBg.split(',');
    if (!cookie.get(cookie_name)) {
      var header_bg_len = header_bg_array.length;
      var random_num = parseInt(Math.random() * header_bg_len);
      cookie.set(cookie_name, random_num, 24 * 60 * 60);
      var img_url = header_bg_array[random_num];
    } else {
      var id = parseInt(cookie.get(cookie_name));
      var img_url = header_bg_array[id];
    }
    // 获取屏幕分辨率
    var screen_w = parseInt(window.screen.width);
    setTimeout(function() {
      var img_elem = new Image();
      img_elem.src = img_url;
      img_elem.onload = function() {
        var site_header_elem = document.getElementById('site-header');
        site_header_elem.style['backgroundImage'] = "url(" + img_url + ")";
      }
    }, 1000);
  }
}